<<<<<<< HEAD
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


/**
 * by liub 20141124 
 * 
 * 会员推广
 * */
class Cps extends MY_Controller {
		
	function __construct(){
		parent::__construct();
		
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
		//****** 上导航栏，点击确定标记
		$this->tab ='cps';
	}
	
	
	//8.1.1	推广会员列表 
	public function cpsuserlist(){
		//TODO 实现
		$data = array();
		$per_page 	= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$strtime	= $this->input->get('strtime');
		$endtime	= $this->input->get('endtime');
		$username	= $this->input->get('username');
		
				$phone		= $this->input->get('phone');
		
		$data['where']['username'] = $username;
		$data['where']['phone'] = $phone;
		
		
		if($strtime != ''){
			$data['where']['strtime'] = $strtime;
		}
		if($endtime != ''){
			$data['where']['endtime'] = $endtime;
		}
		
		$data['page_size']  = STATISTICS_LIST_PAGE_SIZE;//每页行数
		$data['page_start'] = (int)$per_page;//起始页
		$this->load->model('User_model');
		$vdata = $this->User_model->get_cpsuser_list($data);

		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/cps/cpsuserlist/?strtime='.$strtime.'&endtime='.$endtime.'&username='.$username;
		$config['total_rows'] = $vdata['user_count'];
		$config['per_page'] = STATISTICS_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'cpsuserlist';
		
		$this->load->view('/sys_admin/cps/cpsuser_list', $vdata);
	}
	
	// 查看推广会员明细
	public function query(){
		$user_id = $_POST['uid'];
		$this->load->model('User_model', 'user');
		$vdata = $this->user->get_cpuuserdetail_list($user_id);
		$response_html = $this->load->view('/sys_admin/cps/show_cpsuser_info',$vdata,true);
		echo $response_html;
	}
	
	//8.1.2	佣金发放统计表 
	public function cpsmoneylist(){
		$tstart = trim($_REQUEST['tstart']);
		$tend 	= trim($_REQUEST['tend']);
		//TODO 逻辑上有问题
		$currt = strtotime("2014-02-01");
		$start = strtotime("2014-02-01");
		if($tstart != ""){
			$currt = strtotime($tstart.'-01');
			$start = strtotime($tstart.'-01');
		}
		$end   = strtotime(date("Y-m-01"));
		$end 	= strtotime("1 month",$end);
		if($tend != ""){
			$end = strtotime($tend.'-01');
			$end = strtotime("1 month",$end);
		}
		
		$this->load->model('User_model');
		$nstart = 0;
		$index = 0;
		do{
			$nstart = strtotime("1 month",$start);
			$vdata['list'][$index] = $this->User_model->get_cpsmoney_list(array('start_time' =>$start, 'end_time'=> $nstart));
			$vdata['list'][$index]['year'] = date("Y",$start);
			$vdata['list'][$index]['month'] = date("m",$start);
			$start = strtotime("1 month",$start);
			$index++;
		}while($start != $end);
		$vdata['tstart'] 	= $tstart;
		$vdata['tend'] 	= $tend;
		

		/***
		if($type == 'caccount'){
			self::array_sort($vdata['list'],'caccount','DESC');
		}elseif($type == 'saccount'){
			self::array_sort($vdata['list'],'saccount','DESC');
		}elseif($type == 'useracount'){
			self::array_sort($vdata['list'],'useracount','DESC');
		}elseif($type == 'museracount'){
			self::array_sort($vdata['list'],'museracount','DESC');
		}elseif($type == 'rjtmoney'){
			self::array_sort($vdata['list'],'rjtmoney','DESC');
		}elseif($type == 'baccount'){
			self::array_sort($vdata['list'],'baccount','DESC');
		}elseif($type == 'rjcnum'){
			self::array_sort($vdata['list'],'rjcnum','DESC');
		}elseif($type == 'rjye'){
			self::array_sort($vdata['list'],'rjye','DESC');
		}*/
				
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'cpsmoneylist';
		
		//TODO  暂略
		$this->load->view('/sys_admin/cps/cpsmoneylist', $vdata);

	}

	//8.1.3	推广规则设置
	public function set_cps(){
		$this->load->model('cpsrule_model', 'cps');
		$admin = $this->session->userdata('admin_user');
		if(isset($admin['type_id']) && $admin['type_id'] ==1){
			$act = $this->input->post("act");
			//从前台获取传入参数
			$parms = array(	'first_percent'=>$this->input->post("first_percent"),
							'second_percent'=>$this->input->post("second_percent"),
							'fstatus'=>$this->input->post("fstatus"),
							'add_time' => time (), 
							'addip' => $this->input->ip_address (),
							'op_user' => $admin['id'], 
						);
			// TODO 增加日志				
			if($act == 'add'){
				$parms['fstatus'] = 0;
				$res = $this->cps->add($parms);
			}elseif($act == 'set'){
				$id = $this->input->post("id");
				$fstatus = $this->input->post("fstatus");
				if($fstatus ==1){
					$res = $this->cps->change_status($id);
				}else{
					$res = $this->cps->update($id,Array("fstatus" => $fstatus));
				}
			}elseif($act == 'edit'){
				$id = $this->input->post("id");
				$res = $this->cps->update($id,$parms);
			}elseif($act == 'delete'){
				$id = $this->input->post("id");
				$res = $this->cps->update($id,Array("fstatus" => 3));
			}
			if($res>0){
				$ret = array('msg'=>'操作成功');
			}else{
				$ret = array('msg'=>'操作失败');
			}
		}else{
			$ret = array('msg'=>'对不起，权限不足！');
		}
		echo json_encode($ret);
		exit; 
	}
	
	// 查找cps 记录
	public function get_cpsrule(){
		$per_page 	= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$this->load->model('cpsrule_model', 'cps');
		$data = Array();
		$data ['cpsrule_list']= $this->cps->getAll();
		$data['page_size']  = STATISTICS_LIST_PAGE_SIZE;//每页行数
		$data['page_start'] = (int)$per_page;//起始页
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/cps/get_cpsrule';
		$config['total_rows'] = $data['cpsrule_count'];
		$config['per_page'] = STATISTICS_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		$data['tab'] = $this->tab;
		$data['sub'] = 'setcps';
		
		$this->load->view('/sys_admin/cps/setcps', $data);
	}

	//专属客服用户表
	public function kefuuserlist(){
		$data=array();
		$this->load->model('kf_model');
		$this->load->model('user_kf_model');
		$this->load->model('user_model');
		$kefulist=$this->kf_model->get_all();
		//var_dump($_GET['kefuselect']);
		if($_GET['kefuselect']){
			$kf_id=$_GET['kefuselect'];
		}else{
			$kf_id=1;
		}
		
		//echo $kf_id;
		$kefuinfo=$this->kf_model->get_one(array('id'=>$kf_id));//获取客服信息
		$userlist=$this->user_kf_model->kefuuserlist($kf_id);//当前客服获取投资人列表

		$kf_name_num=$this->user_kf_model->countUser($kf_id);//计算投资人个数
		$kf_click=$this->user_kf_model->click_num($kf_id);//客服被点击的总次数
		$kf_click=intval($kf_click);
		foreach ($userlist as $key=>$value) {			
			$data['userlist'][$key]=$this->user_model->get_all_by_id($value['userid']);
			$data['userlist'][$key]['addtime_kf']=$value['addtime'];
			$data['userlist'][$key]['kf_name']=$kefuinfo['kf_name'];
			$data['userlist'][$key]['click_num']=$value['click_num'];
		}
		$data['kf_id']=$kf_id;//客服名称		
		$data['kf_name']=$kefuinfo['kf_name'];//客服名称
		$data['kf_name_num']=$kf_name_num;//计算投资人个数
		$data['kf_click']=$kf_click;//客服被点击的总次数
		$data['kf_use']=$kefuinfo['status'];//客服正常使用
		$data['kf_img']=$kefuinfo['img'];//客服头像
		$data['kefulist']=$kefulist;//所有客服列表

		$data['tab'] = $this->tab;
		$data['sub'] = 'kefuUserlist';
		$this->load->view('/sys_admin/cps/kefuUserlist', $data);
	}

}
=======
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


/**
 * by liub 20141124 
 * 
 * 会员推广
 * */
class Cps extends MY_Controller {
    	
	function __construct(){
		parent::__construct();
		
		/** 登陆验证 */
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /sys_admin/login');
			exit;
		}
		//****** 上导航栏，点击确定标记
		$this->tab ='cps';
	}
	
	
	//8.1.1	推广会员列表 
	public function cpsuserlist(){
		//TODO 实现
		$data = array();
		$per_page 	= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$strtime	= $this->input->get('strtime');
		$endtime	= $this->input->get('endtime');
		$username	= $this->input->get('username');
		
				$phone		= $this->input->get('phone');
		
		$data['where']['username'] = $username;
		$data['where']['phone'] = $phone;
		
		
		if($strtime != ''){
			$data['where']['strtime'] = $strtime;
		}
		if($endtime != ''){
			$data['where']['endtime'] = $endtime;
		}
		
		$data['page_size']  = STATISTICS_LIST_PAGE_SIZE;//每页行数
		$data['page_start'] = (int)$per_page;//起始页
		$this->load->model('User_model');
		$vdata = $this->User_model->get_cpsuser_list($data);

		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/cps/cpsuserlist/?strtime='.$strtime.'&endtime='.$endtime.'&username='.$username;
		$config['total_rows'] = $vdata['user_count'];
		$config['per_page'] = STATISTICS_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'cpsuserlist';
		
		$this->load->view('/sys_admin/cps/cpsuser_list', $vdata);
	}
	
	// 查看推广会员明细
	public function query(){
		$user_id = $_POST['uid'];
		$this->load->model('User_model', 'user');
		$vdata = $this->user->get_cpuuserdetail_list($user_id);
		$response_html = $this->load->view('/sys_admin/cps/show_cpsuser_info',$vdata,true);
		echo $response_html;
	}
	
	//8.1.2	佣金发放统计表 
	public function cpsmoneylist(){
		$tstart = trim($_REQUEST['tstart']);
		$tend 	= trim($_REQUEST['tend']);
		//TODO 逻辑上有问题
		$currt = strtotime("2014-02-01");
		$start = strtotime("2014-02-01");
		if($tstart != ""){
			$currt = strtotime($tstart.'-01');
			$start = strtotime($tstart.'-01');
		}
		$end   = strtotime(date("Y-m-01"));
		$end 	= strtotime("1 month",$end);
		if($tend != ""){
			$end = strtotime($tend.'-01');
			$end = strtotime("1 month",$end);
		}
		
		$this->load->model('User_model');
		$nstart = 0;
		$index = 0;
		do{
			$nstart = strtotime("1 month",$start);
			$vdata['list'][$index] = $this->User_model->get_cpsmoney_list(array('start_time' =>$start, 'end_time'=> $nstart));
			$vdata['list'][$index]['year'] = date("Y",$start);
			$vdata['list'][$index]['month'] = date("m",$start);
			$start = strtotime("1 month",$start);
			$index++;
		}while($start != $end);
		$vdata['tstart'] 	= $tstart;
		$vdata['tend'] 	= $tend;
		

		/***
		if($type == 'caccount'){
			self::array_sort($vdata['list'],'caccount','DESC');
		}elseif($type == 'saccount'){
			self::array_sort($vdata['list'],'saccount','DESC');
		}elseif($type == 'useracount'){
			self::array_sort($vdata['list'],'useracount','DESC');
		}elseif($type == 'museracount'){
			self::array_sort($vdata['list'],'museracount','DESC');
		}elseif($type == 'rjtmoney'){
			self::array_sort($vdata['list'],'rjtmoney','DESC');
		}elseif($type == 'baccount'){
			self::array_sort($vdata['list'],'baccount','DESC');
		}elseif($type == 'rjcnum'){
			self::array_sort($vdata['list'],'rjcnum','DESC');
		}elseif($type == 'rjye'){
			self::array_sort($vdata['list'],'rjye','DESC');
		}*/
				
		$vdata['tab'] = $this->tab;
		$vdata['sub'] = 'cpsmoneylist';
		
		//TODO  暂略
		$this->load->view('/sys_admin/cps/cpsmoneylist', $vdata);

	}

	//8.1.3	推广规则设置
	public function set_cps(){
		$this->load->model('cpsrule_model', 'cps');
		$admin = $this->session->userdata('admin_user');
		if(isset($admin['type_id']) && $admin['type_id'] ==1){
			$act = $this->input->post("act");
			//从前台获取传入参数
			$parms = array(	'first_percent'=>$this->input->post("first_percent"),
							'second_percent'=>$this->input->post("second_percent"),
							'fstatus'=>$this->input->post("fstatus"),
							'add_time' => time (), 
							'addip' => $this->input->ip_address (),
							'op_user' => $admin['id'], 
						);
			// TODO 增加日志				
			if($act == 'add'){
				$parms['fstatus'] = 0;
				$res = $this->cps->add($parms);
			}elseif($act == 'set'){
				$id = $this->input->post("id");
				$fstatus = $this->input->post("fstatus");
				if($fstatus ==1){
					$res = $this->cps->change_status($id);
				}else{
					$res = $this->cps->update($id,Array("fstatus" => $fstatus));
				}
			}elseif($act == 'edit'){
				$id = $this->input->post("id");
				$res = $this->cps->update($id,$parms);
			}elseif($act == 'delete'){
				$id = $this->input->post("id");
				$res = $this->cps->update($id,Array("fstatus" => 3));
			}
			if($res>0){
				$ret = array('msg'=>'操作成功');
			}else{
				$ret = array('msg'=>'操作失败');
			}
		}else{
			$ret = array('msg'=>'对不起，权限不足！');
		}
		echo json_encode($ret);
		exit; 
	}
	
	// 查找cps 记录
	public function get_cpsrule(){
		$per_page 	= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$this->load->model('cpsrule_model', 'cps');
		$data = Array();
		$data ['cpsrule_list']= $this->cps->getAll();
		$data['page_size']  = STATISTICS_LIST_PAGE_SIZE;//每页行数
		$data['page_start'] = (int)$per_page;//起始页
		//分页
		$this->load->library('pagination');
		$config['base_url'] = '/sys_admin/cps/get_cpsrule';
		$config['total_rows'] = $data['cpsrule_count'];
		$config['per_page'] = STATISTICS_LIST_PAGE_SIZE; 
		$this->pagination->initialize($config); 
		$data['tab'] = $this->tab;
		$data['sub'] = 'setcps';
		
		$this->load->view('/sys_admin/cps/setcps', $data);
	}
	
	//专属客服用户表
	public function kefuuserlist(){
		$data=array();
		$this->load->model('kf_model');
		$this->load->model('user_kf_model');
		$this->load->model('user_model');
		$kefulist=$this->kf_model->get_all();
		//var_dump($_GET['kefuselect']);
		if($_GET['kefuselect']){
			$kf_id=$_GET['kefuselect'];
		}else{
			$kf_id=1;
		}
		
		//echo $kf_id;
		$kefuinfo=$this->kf_model->get_one(array('id'=>$kf_id));//获取客服信息
		$userlist=$this->user_kf_model->kefuuserlist($kf_id);//当前客服获取投资人列表

		$kf_name_num=$this->user_kf_model->countUser($kf_id);//计算投资人个数
		$kf_click=$this->user_kf_model->click_num($kf_id);//客服被点击的总次数
		$kf_click=intval($kf_click);
		foreach ($userlist as $key=>$value) {			
			$data['userlist'][$key]=$this->user_model->get_all_by_id($value['userid']);
			$data['userlist'][$key]['addtime_kf']=$value['addtime'];
			$data['userlist'][$key]['kf_name']=$kefuinfo['kf_name'];
			$data['userlist'][$key]['click_num']=$value['click_num'];
		}
		$data['kf_id']=$kf_id;//客服名称		
		$data['kf_name']=$kefuinfo['kf_name'];//客服名称
		$data['kf_name_num']=$kf_name_num;//计算投资人个数
		$data['kf_click']=$kf_click;//客服被点击的总次数
		$data['kf_use']=$kefuinfo['status'];//客服正常使用
		$data['kf_img']=$kefuinfo['img'];//客服头像
		$data['kefulist']=$kefulist;//所有客服列表

		$data['tab'] = $this->tab;
		$data['sub'] = 'kefuUserlist';
		$this->load->view('/sys_admin/cps/kefuUserlist', $data);
	}
}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
